/**
 * teachingJournal.js
 * 教学日志reducer
 *
 * created by xurui
 * version 1.0.0
 * 2016年03月29日
 */
import { CITY, COUNTY, SCHOOL } from '../../../constants/area';
import { merge } from 'lodash/object';
import { cloneDeep }from 'lodash/lang';

import { 
	GET_DETAIL_REQUEST,
	GET_DETAIL_SUCCESS,
	GET_DETAIL_FALIURE,
	SELECT_TEACHERS_INFORMATION_PAGE
} from '../actions/teachingJournal';

/**
 * 初始鉴权信息页面状态
 * @type {Object}
 */
export const INITIALIZE_STATE = {
	message:'',
	// 正在与服务器通讯
	isFetching:false,
	//总条数
	pageSize:0,
	//总页数
	pageIndex:0,
	//当前页码
	currentPageIndex:1,
	//相关教师数据详情
	detail:[]
	
};
/**
 * 处理鉴权信息
 * @param  {Object} state  当前页面状态
 * @param  {Object} action 请求描述对象
 * @return {Object}        当前页面新状态
 */
export default function teachingJournal(state = INITIALIZE_STATE, action = {}) {
	let { type, ...others } = action;
	switch(type) {
		/*翻页*/
		case SELECT_TEACHERS_INFORMATION_PAGE:
		{	let { currentPageIndex } = others.payload;
			let newState = Object.assign({},state,{
				currentPageIndex
			});
			return newState
		}
		/**
		 * 异步请求教师日志列表
		 * @type {[type]}
		 */
		case GET_DETAIL_REQUEST:
		{
			let newState = Object.assign({},state,{
				isFetching:true
			});
			
			return newState
		};
		case GET_DETAIL_SUCCESS:
		{
			let { detail, pageIndex, pageSize } = others.payload;
			let newState = Object.assign({},state,{
				isFetching:false,
				detail,
				pageIndex,
				pageSize
			});
			return newState
		};
		case GET_DETAIL_FALIURE:
		{
			let { errorMessage } = others.payload;
			let newState = Object.assign({},state,{
				message:errorMessage,
				isFetching:false
			});
			return newState
		};
		default:
			return state;
	}
}